﻿using System;
using System.IO;
using System.Threading.Tasks;
using Icinetic.FeedCategorySample.Services.Repositories;
using Icinetic.FeedCategorySample.ViewModel;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;

namespace FeedCategorySample.Test
{
    [TestClass]
    public class SearchResultsViewModelTest
    {
        private const string SEARCH_TEXT = "XBox";

        private string feedUrl = Icinetic.FeedCategorySample.App.FeedUrl;
        private string dbPath = BaseRepository.DbPath;

        [TestInitialize]
        public void TestInitialize()
        {
            Icinetic.FeedCategorySample.App.FeedUrl = "testfeed.xml";
            BaseRepository.DbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "FeedCategorySampleTestDB.db");
            BaseRepository.Initialize();
        }

        [TestCleanup]
        public void TestCleanup()
        {
            Icinetic.FeedCategorySample.App.FeedUrl = feedUrl;
            BaseRepository.DbPath = dbPath;
        }

        [TestMethod]
        public async Task LoadTest()
        {
            SearchResultsViewModel model = new SearchResultsViewModel(Guid.NewGuid().ToString(), null);

            await model.Load(SEARCH_TEXT);

            Assert.IsTrue(model.Filters.Count > 0);
            Assert.IsTrue(model.ResultsHistory.Count > 0);
        }
    }
}
